package com.situ.personal.service.impl;

import java.util.List;

import com.situ.personal.dao.IEmployeeDao;
import com.situ.personal.dao.impl.EmployeeDaoImpl;
import com.situ.personal.pojo.Employee;
import com.situ.personal.pojo.vo.EmployeeDeptVO;
import com.situ.personal.service.IEmployeeService;
import com.situ.personal.util.LayUITableResult;
import com.situ.personal.util.MD5Util;

// 业务逻辑
public class EmployeeServiceImpl implements IEmployeeService{
	private IEmployeeDao employeeDao = new EmployeeDaoImpl();

	@Override
	public List<Employee> selectAll() {
		return employeeDao.selectAll();
	}

	@Override
	public void deleteById(Integer id) {
		employeeDao.deleteById(id);
	}

	@Override
	public LayUITableResult selectByPage(Integer page, Integer limit) {
		// 体现Service业务
		// 分页要完成两条sql语句查找：1、当前页的数据 2、总的数量
		int offset = (page - 1) * limit;
		List<EmployeeDeptVO> list = employeeDao.selectByPage(offset, limit);
		
		long totalCount = employeeDao.selectTotalCount();
		
		return LayUITableResult.ok(list, totalCount);
	}

	@Override
	public void add(Employee employee) {
		employeeDao.add(employee);
	}

	@Override
	public void deleteAll(String[] array) {
		for (String id : array) {
			employeeDao.deleteById(Integer.parseInt(id));
		}
	}

	@Override
	public Employee selectById(Integer id) {
		return employeeDao.selectById(id);
	}

	@Override
	public void update(Employee employee) {
		employeeDao.update(employee);
	}
}
